//
//  BNMainViewController.swift
//  BNWeiBo
//
//  Created by ba.o0 on 16/8/10.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class BNMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        tabBarButtonClick()

       //2.0
        //实例化自定义tabBar
        let tabBar = BNTabBar()
       
        //设置代理
        tabBar.BNDelegate = self
    
        //通过KVC 给只读属性赋值
        setValue(tabBar, forKey: "tabBar")
        
        //首页
        addChildViewController(BNHomeVC(),imgName:"tabbar_home",title:"首页")
        //消息
        addChildViewController(BNMessageVC(), imgName: "tabbar_message_center", title: "消息")
        //发现
        addChildViewController(BNDiscoverVC(), imgName: "tabbar_discover", title: "发现")
        //我
        addChildViewController(BNProfileVC(), imgName: "tabbar_profile", title: "我")
    }

    //2.0
    /**
    添加子控制器
    
    - parameter vc:      控制器
    - parameter imgName: 图片名称
    - parameter title:   title
    */
    
    func addChildViewController(vc:UIViewController,imgName:String,title:String) {
        //设置title
        vc.title = title
        
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        //设置图片
        vc.tabBarItem.image = UIImage(named:imgName)
        //AlwaysOriginal图片渲染方式
        vc.tabBarItem.selectedImage = UIImage(named:"\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //添加子控制器
        addChildViewController(UINavigationController(rootViewController: vc))
    }
    }
    extension BNMainViewController:BNTabBarDelegate{
        func tabBarButtonClick(){
            print("撰写按钮点击啦")
        
    }
}













